接續上一篇影片播放器, 這篇要介紹的是子母畫面PIP(Picture in Picture)功能,最常見的就是應用在"影片播放"和"地圖導航"時離開該應用程式,畫面會變成懸浮的小型視窗繼續顯示。
<activity
android:name=".MainActivity"
android:supportsPictureInPicture="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
...
</activity>
public void myButton(View view) {
this.enterPictureInPictureMode(null); //切換到子母畫面
}
/**
* 子母畫面切換時 Activity上的元件改變. 例如:可視狀態的切換
*/
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
if (isInPictureInPictureMode) {
view.btnPIP.setVisibility(View.INVISIBLE); // 隱藏子母按鈕
} else {
view.btnPIP.setVisibility(View.VISIBLE); // 顯示子母按鈕
}
}